<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    //左边只和相加大于右边之和
    function fn(nums) {
        let sum = nums.reduce((cur, pre) => cur + pre, 0)
        let n = nums.length
        let leftSum = 0;
        let i = 0;
        while (i < n) {
            let rightSum = sum - leftSum - nums[i]
            if (leftSum === rightSum) {
                return i
            }
            leftSum += nums[i]
            i++
        }
        return -1
    }
    console.log(fn([1,2,3,4,5]));

</script>

</html>